package com.gateway.dao;

import java.io.IOException;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class BaseDao {

  private static SqlSessionFactory sessionFactory;
  static {
    SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
    try {
      sessionFactory=builder.build(Resources.getResourceAsReader("mybatis-Config.xml"));
    } catch(IOException e) {
      e.printStackTrace();
    }
  }

  protected SqlSessionFactory getSessionFactory() {
    return sessionFactory;
  }

  protected SqlSession openSession() {
    return sessionFactory.openSession(true);
  }
}
